package com.zhongkun.datahome.web.app;

import com.zhongkun.datahome.common.annotation.Log;
import com.zhongkun.datahome.common.core.controller.BaseController;
import com.zhongkun.datahome.common.core.domain.R;
import com.zhongkun.datahome.common.enums.BusinessType;
import com.zhongkun.datahome.common.utils.SecurityUtils;
import com.zhongkun.datahome.service.req.cmd.task.TaskCmd;
import com.zhongkun.datahome.service.req.cmd.task.TaskProcessCmd;
import com.zhongkun.datahome.service.res.task.MyTaskVo;
import com.zhongkun.datahome.service.res.task.TaskVo;
import com.zhongkun.datahome.service.service.ITaskService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 任务Controller
 *
 * @author ruoyi
 * @date 2025-04-14
 */
@RestController
@RequestMapping("/app/task")
public class TaskAppController extends BaseController {
    @Resource
    private ITaskService taskService;

    @ApiOperation("我的任务")
    @GetMapping("/myTask")
    public R<MyTaskVo> myTask(boolean employeeFlag) {
        return R.ok(taskService.myTask(SecurityUtils.getTenantUserId(), employeeFlag));
    }

    @ApiOperation("我的任务")
    @GetMapping("/receiveTaskCount")
    public R<Long> receiveTaskCount() {
        return R.ok(taskService.queryReceiveTaskCount(SecurityUtils.getTenantUserId()));
    }

    @ApiOperation("新增任务")
    @Log(title = "任务", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R<Long> add(@RequestBody TaskCmd cmd) {
        return R.ok(taskService.add(cmd));
    }

    @ApiOperation("继续处理任务")
    @Log(title = "任务", businessType = BusinessType.UPDATE)
    @PostMapping("/process")
    public R<Long> process(@RequestBody TaskProcessCmd cmd) {
        return R.ok(taskService.process(cmd));
    }

    @ApiOperation("获取任务详细信息")
    @GetMapping(value = "/{id}")
    public R<TaskVo> getInfo(@PathVariable("id") Long id) {
        return R.ok(taskService.getInfo(id));
    }
}